<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>安全检查</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="statics/css/style.css" />
    <script src="statics/js/flexible.js" type="text/javascript" charset="utf-8"></script>
    <script src="statics/js/zepto.min.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div id='app'>
        <div class="top">
            <a href="../index.html"><i></i></a> 安全检查
        </div>
        <div class="fwpj">
            <van-cell is-link @click="show = true" title="选择房间" :value="fieldValue" size="large"></van-cell>
            <!-- <van-popup v-model="show" round position="bottom">
                <van-cascader v-model="cascaderValue" title="请选择任务与房间" :options="columns1" @close="show = false" @change="onChangeCheck" @finish="onFinish" />
            </van-popup> -->
        </div>

        <div class="form-box">
            <!--打分-->
            <div class="jtssk">
                <p class="title"><span>-</span>打分<span>-</span></p>
                <div class="items">

                    <div class="item" v-for="(item, index) in thischeck7s">
                        <span>{{item.TITLE}}</span>
                        <div class="star">
                            <span class="on" @click="item.score1=(item.SCORE/5)"></span>
                            <span @click="item.score1=(item.SCORE/5*2)"></span>
                            <span @click="item.score1=(item.SCORE/5*3)"></span>
                            <span @click="item.score1=(item.SCORE/5*4)"></span>
                            <span @click="item.score1=(item.SCORE)"></span>
                        </div>
                    </div>

                </div>
            </div>
            <!--选择标签-->
            <div class="xzbq">
                <p class="title"><span>-</span>上传<span>-</span></p>
                <div class="tags" style="padding-right: 10px;padding-left: 10px;">
                    <van-uploader v-model="fileList" :after-read="afterRead" accept="image/*" capture="camera" />
                </div>
            </div>
            <div class="remark">
                <textarea v-model="question" name="content" placeholder="请输入问题描述..."></textarea>
            </div>
            <div class="remark">
                <textarea v-model="remarks" name="content" placeholder="请输入备注..."></textarea>
            </div>

        </div>
        <div class="submit">
            <button v-if="showBtn" @click="onSubmit">提交</button>
        </div>



    </div>
</body>

<script type="text/javascript">
    function getstar() {
        $('.star span').click(function() {
            $(this).parent().find('span').removeClass('on')
            var index = $(this).index();
            $(this).parent().find('span').each(function() {
                if (index < 0) {
                    return
                }
                $(this).addClass('on');
                index--
            })
        })
        $('.tags ul li').click(function() {
            $(this).toggleClass('on')
        })
    }
</script>


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.12/lib/index.css" />
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script> -->

<script src="../js/vue/vue.js"></script>
<script src="../js/iview/iview.min.js"></script>
<script src="../js/jsCookie/js.cookie.min.js"></script>
<script src="../js/axios/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vant@2.12/lib/vant.min.js"></script>



<script>
    var app = new Vue({
        el: "#app",
        data: {
            message: "Hello Vue!",
            columns1: [],
            thischeck7s: [],
            checkList: [],
            checkUserScopeList: [],
            checkId: '',
            scopeId: '',
            show: false,
            fieldValue: '',
            cascaderValue: '',
            rectify: 0,
            remarks: '',
            question: '',
            testId: '',
            fileList: [],
            fileNameList: [],
            showBtn: true,
            t: '',
        },
        methods: {
            getQueryVariable(variable) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i=0;i<vars.length;i++) {
                    var pair = vars[i].split("=");
                    if(pair[0] == variable){return pair[1];}
                }
                return(false);
            },
            getFangjian() {
                let formData = new FormData();
                console.log('this.$route', this.$route)
                formData.append("testId", this.getQueryVariable('testId'));
                formData.append("userId", this.user.id);
                axios
                    .post(
                        "http://10.11.41.128:30010/check/findCheckUserScope?ticket=" + Cookies.get('ticket'),
                        formData, {
                            headers: {
                                "Content-Type": "multipart/form-data",
                                "token": this.user.token,
                            },
                        }
                    )
                    .then(res => {
                        if (res.data === null || res.data === " ") return;
                        if (res.data.status === 1 && res.data.data && res.data.data.dataList && res.data.data.dataList.length > 0) {
                            console.log('获取房间id', res.data)
                            this.room = res.data.data.dataList[0]
                            this.fieldValue = `${this.room.CHECKTITLE} / ${this.room.TESTNAME}`
                            this.checkId = this.room.CHECKID
                            this.scopeId = this.room.TESTID
                        } else {
                            this.$notify({
                                type: 'danger',
                                message: '获取房间失败'
                            });
                            if (res.data.msg === "未登录") {
                                window.location.href = "login.html"
                            }
                        }
                    });
            },
            findCheck7S() {
                let formData = new FormData();
                formData.append("randow", Math.random());
                axios
                    .post(
                        "http://10.11.41.128:30010/check7S/findCheck7S?ticket=" + Cookies.get('ticket'), formData, {
                            headers: {
                                "Content-Type": "multipart/form-data",
                                "token": this.user.token,
                            },
                        }
                    )
                    .then((res) => {

                        if (res.data === null || res.data === "") return;
                        if (res.data.data) {
                            this.thischeck7s = res.data.data.dataList
                            this.thischeck7s.forEach(item => {
                                item.score1 = 2
                            })
                            setTimeout(getstar, 500)

                        } else {
                            this.$notify({
                                type: 'danger',
                                message: '加载失败' + res.data.msg
                            });
                            if (res.data.msg === "未登录") {
                                window.location.href = "../login.html"
                            }
                        }
                    });
            },
            CheckByUserId() {
                let formData = new FormData();
                formData.append("randow", Math.random());
                formData.append("userId", this.user.id);
                axios
                    .post(
                        "http://10.11.41.128:30010/check/findCheckByUserId?ticket=" + Cookies.get('ticket'), formData, {
                            headers: {
                                "Content-Type": "multipart/form-data",
                                "token": this.user.token,
                            },
                        }
                    )
                    .then((res) => {

                        if (res.data === null || res.data === "") return;
                        if (res.data.data) {
                            this.checkList = res.data.data.dataList
                            this.checkList.forEach(function(item, idnex, array) {
                                this.app.columns1.push({
                                    text: item.TITLE,
                                    value: item.ID,
                                    children: [],
                                })
                            })

                        } else {
                            this.$notify({
                                type: 'danger',
                                message: '加载失败' + res.data.msg
                            });
                            if (res.data.msg === "未登录") {
                                window.location.href = "../login.html"
                            }
                        }
                    });
            },
            CheckUserScope(obj) {
                let formData = new FormData();
                formData.append("randow", Math.random());
                formData.append("userId", this.user.id);
                formData.append("checkId", obj.selectedOptions[0].value);
                axios
                    .post(
                        "http://10.11.41.128:30010/check/findCheckUserScope?ticket=" + Cookies.get('ticket'), formData, {
                            headers: {
                                "Content-Type": "multipart/form-data",
                                "token": this.user.token,
                            },
                        }
                    )
                    .then((res) => {

                        if (res.data === null || res.data === "") return;
                        if (res.data.data) {
                            this.checkUserScopeList = res.data.data.dataList
                            this.checkUserScopeList.forEach(function(item, idnex, array) {
                                obj.selectedOptions[0].children.push({
                                    text: item.TESTNAME,
                                    value: item.TESTID
                                })
                            })

                        } else {
                            this.$notify({
                                type: 'danger',
                                message: '加载失败' + res.data.msg
                            });
                            if (res.data.msg === "未登录") {
                                window.location.href = "../login.html"
                            }
                        }
                    });
            },
            getCookieUser() {
                let userJson = Cookies.get('userInfo');
                if (!userJson) {
                    this.$notify({
                        type: 'danger',
                        message: '请先登录'
                    });
                    window.location.href = '../login.html'
                    return
                }
                this.user = JSON.parse(userJson)
                if (!this.user) {
                    this.$notify({
                        type: 'danger',
                        message: '请先登录'
                    });
                    window.location.href = '../login.html'
                    return
                }
                this.findCheck7S()
                this.getFangjian()
            },
            onSubmit() {
                this.rectify = 0
                let check7SStr = ''
                this.thischeck7s.forEach(function(item, idnex, array) {
                    if (item.score1 != item.SCORE) {
                        this.app.rectify = 1
                        console.log(item)
                    }
                    check7SStr += item.ID + '|||' + item.score1 + '@@@'
                })
                if (this.checkId.length <= 0) {
                    this.$dialog.alert({
                        message: '请选择任务',
                        theme: 'round-button',
                    }).then(() => {});
                    return
                }
                if (this.scopeId.length <= 0) {
                    this.$dialog.alert({
                        message: '请选择房间',
                        theme: 'round-button',
                    }).then(() => {});
                    return
                }
                if (this.rectify != 0) {
                    if (this.fileNameList.length <= 0) {
                        this.$dialog.alert({
                            message: '请上传图片',
                            theme: 'round-button',
                        }).then(() => {});
                        return
                    }
                    if (this.question.length <= 0) {
                        this.$dialog.alert({
                            message: '请填写问题描述',
                            theme: 'round-button',
                        }).then(() => {});
                        return
                    }
                }
                console.log(check7SStr)
                let formData = new FormData();
                // formData.append("randow", Math.random());
                formData.append("checkId", this.checkId);
                formData.append("testId", this.scopeId);
                formData.append("isRectify", this.rectify);
                formData.append("check7S", check7SStr);
                formData.append("remarks", this.remarks);
                formData.append("question", this.question);
                formData.append("enclosure", this.fileNameList.join(','));
                formData.append("instumentId", '');

                this.showBtn = false
                axios
                    .post(
                        "http://10.11.41.128:30010/checkDay/add?ticket=" + Cookies.get('ticket'), formData, {
                            headers: {
                                "Content-Type": "multipart/form-data",
                                "token": this.user.token,
                            },
                        }
                    )
                    .then((res) => {
                        if (res.data === null || res.data === "") return;
                        if (res.data.msg === '请求成功') {
                            this.$notify({
                                type: 'success',
                                message: '提交成功！'
                            });

                            setTimeout(() => {
                                this.showBtn = true
                                // location.reload();
                                window.location.href = '/index.html'
                            }, 1500);
                        } else {
                            this.showBtn = true
                            this.$notify({
                                type: 'danger',
                                message: '加载失败' + res.data.msg
                            });
                            if (res.data.msg === "未登录") {
                                window.location.href = "../login.html"
                            }
                        }
                    });
            },
            onChangeCheck(obj) {
                this.CheckUserScope(obj)
            },
            onFinish({
                selectedOptions
            }) {
                this.show = false;
                this.fieldValue = selectedOptions.map((option) => option.text).join('/');
                this.checkId = selectedOptions[0].value
                this.scopeId = selectedOptions[1].value
            },
            afterRead(file) {
                file.status = 'uploading'
                file.message = '上传中...'
                    // 此时可以自行将文件上传至服务器
                console.log(file);
                // setTimeout(() => {
                //   file.status = 'done';
                //   file.message = '上传完成';
                // }, 1000);

                let formData = new FormData();
                formData.append("file", file.file);


                axios
                    .post(
                        "http://10.11.41.128:30010/public/file/upload?ticket=" + Cookies.get('ticket'), formData, {
                            headers: {
                                "Content-Type": "multipart/form-data",
                                "token": this.user.token,
                            },
                        }
                    )
                    .then((res) => {

                        if (res.data === null || res.data === "") return;
                        if (res.data.data) {
                            this.fileNameList.push(res.data.data)
                            file.status = 'done';
                            file.message = '上传完成';
                        } else {
                            this.$notify({
                                type: 'danger',
                                message: '加载失败' + res.data.msg
                            });
                            if (res.data.msg === "未登录") {
                                window.location.href = "../login.html"
                            }
                        }
                    });
            },


        },
        mounted: function() {
            this.getCookieUser();
            this.CheckByUserId();
            this.t = this.f('ticket');
        },
    });
</script>

</html>